﻿using System;
using System.Collections.Generic;
using System.Text;

namespace InHouse.SharedLibraries.DataContext
{
    public class DataContextException : Exception
    {
        //Dictionary<string, object> _data;
        public DataContextException(string message, Exception inner) : base(message, inner) { }
       

        public DataContextException(string message) : base(message) { }
        

        public DataContextException() : base() { }


        public override string ToString()
        {
            StringBuilder exceptionString = new StringBuilder(this.Message);
            exceptionString.Append(Environment.NewLine);

            if (Data != null && Data.Count > 0)
            {
                exceptionString.Append("The following information might be useful in diagnosing any problem:\n");

                foreach (string info in Data.Keys)
                {
                    exceptionString.Append(info);
                    exceptionString.Append("\t");
                    exceptionString.Append(Data[info] ?? "null");
                    exceptionString.AppendFormat(Environment.NewLine);
                }
            }

            return base.ToString() + "\n" + exceptionString.ToString();
        }
    }
}
